trigger MileageTrigger on Mileage__c (before insert) {
  MileageLogic mlogic = new MileageLogic();
    
  private Mileage__c[] objs = Trigger.new;
  for (Mileage__c obj: objs) {
    if (mlogic.areMilesAllowed(obj.miles__c)) {        
      String id = obj.Contact__c;
      Contact[] contacts = [select Name from Contact where id = :id];
      if (contacts != null) {
        obj.Purpose__c = 'Met with ' + contacts[0].Name;
      }
    } else {
    String errormsg = String.valueOf(obj.miles__c) + ' miles would exceed allowable total mileage for today.';
    obj.addError(errormsg);
      obj.miles__c.addError('Enter a smaller number');
    }
  }
}